﻿using Sino.CapacityCloud.Repositories.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Sino.CapacityCloud.WebApi
{

    public static class LineExtensions
    {

        public static bool IsCompatiable(this Line self, Line other)
        {
            return IsCompatibleLine(Tuple.Create(self.StartingPlaceCode, self.DestinationCode),
                Tuple.Create(other.StartingPlaceCode, other.DestinationCode));
        }

        public static bool IsCompatiable(this TransportLinkage self, TransportLinkage other)
        {
            return IsCompatibleLine(Tuple.Create(self.StartingPlaceCode, self.DestinationPlaceCode), 
                Tuple.Create(other.StartingPlaceCode, other.DestinationPlaceCode));
        }

        public static bool IsCompatibleLine(Tuple<string, string> a, Tuple<string, string> b)
        {
            try
            {
                return a.Item1.StartsWith(b.Item1) && a.Item2.StartsWith(b.Item2);
            }
            catch
            {
                return false;
            }
        }

    }

}